import { getData } from "./data";
import * as tfvis from "@tensorflow/tfjs-vis";
import * as tf from "@tensorflow/tfjs";
window.onload = async function () {
  const data = getData(200, 3);
  tfvis.render.scatterplot(
    { name: "Training Data" },
    {
      values: [
        data.filter((p) => p.label === 1),
        data.filter((p) => p.label === 0),
      ],
    },
  );
  const model = tf.sequential();
  model.add(tf.layers.dense({
    units: 10,
    inputShape:[2],
    activation: "relu",
    kernelRegularizer: tf.regularizers.l2({l2: 1}),
  }))
  // model.add(tf.layers.dropout({rate: 0.9}))
  model.add(tf.layers.dense({
    units: 1,
    activation: "sigmoid",
  }))
  model.compile({
    optimizer: tf.train.adam(0.1),
    loss: tf.losses.logLoss,
  });
  const inputs = tf.tensor2d(data.map((p) => [p.x, p.y]));
  const labels = tf.tensor1d(data.map((p) => p.label));
  // await model.fit(inputs, labels, {
  //   validationSplit: 0.2,
  //   epochs: 200,
  //   callbacks: tfvis.show.fitCallbacks(
  //     { name: "训练结果" },
  //     ["loss", 'val_loss'],
  //     { height: 200, callbacks: ["onEpochEnd"] }
  //   ),
  // });
};